package servlet;

import java.io.IOException;

import javax.imageio.spi.RegisterableService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Employee;
import service.EmployeeService;
import service.impl.EmployeeServiceImpl;

//声明url访问形式
@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet{
	private EmployeeService employeeServiceImpl=new EmployeeServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO 自动生成的方法存根
//		String name=req.getParameter("name");
//		String username=req.getParameter("username");
//		String password=req.getParameter("password");
//		String phone=req.getParameter("phone");
//		String email=req.getParameter("email");
//		int departmentId=Integer.parseInt(req.getParameter("department"));
//		String role=req.getParameter("role");
		//创建一个employee对象
		Employee  employee=new Employee();
		employee.setEmployeename(req.getParameter("name"));
		employee.setUsername(req.getParameter("username"));
		employee.setDepartmentid(Integer.parseInt(req.getParameter("department")));
		employee.setEmail(req.getParameter("email"));
		employee.setPassword(req.getParameter("password"));
		employee.setPhone(req.getParameter("phone"));
		employee.setRole(req.getParameter("role"));
		//调用service层的注册方法
		employeeServiceImpl.register(employee);
		resp.sendRedirect("login.jsp");
		
	}

}
